package interfazGrafica;

import herramientas.BarThread;

import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import java.awt.Dimension;
import javax.swing.JTextArea;
import java.awt.Rectangle;
import java.lang.reflect.InvocationTargetException;
import java.util.Random;

import javax.swing.JProgressBar;
import javax.swing.JButton;

public class Carrera extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JProgressBar jProgressBar1 = null;
	private JProgressBar jProgressBar2 = null;
	private JProgressBar jProgressBar3 = null;
	private JButton jButtonComenzar = null;
	/**
	 * This is the default constructor
	 */
	public Carrera() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(668, 416);
		this.setContentPane(getJContentPane());
		this.setTitle("JFrame");
		
		
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJProgressBar1(), null);
			jContentPane.add(getJProgressBar2(), null);
			jContentPane.add(getJProgressBar3(), null);
			jContentPane.add(getJButtonComenzar(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jProgressBar1	
	 * 	
	 * @return javax.swing.JProgressBar	
	 */
	private JProgressBar getJProgressBar1() {
		if (jProgressBar1 == null) {
			jProgressBar1 = new JProgressBar();
			jProgressBar1.setBounds(new Rectangle(23, 27, 606, 38));
			
		}
		return jProgressBar1;
	}

	/**
	 * This method initializes jProgressBar2	
	 * 	
	 * @return javax.swing.JProgressBar	
	 */
	private JProgressBar getJProgressBar2() {
		if (jProgressBar2 == null) {
			jProgressBar2 = new JProgressBar();
			jProgressBar2.setBounds(new Rectangle(23, 71, 606, 38));
		}
		return jProgressBar2;
	}

	/**
	 * This method initializes jProgressBar3	
	 * 	
	 * @return javax.swing.JProgressBar	
	 */
	private JProgressBar getJProgressBar3() {
		if (jProgressBar3 == null) {
			jProgressBar3 = new JProgressBar();
			jProgressBar3.setBounds(new Rectangle(22, 114, 606, 38));
		}
		return jProgressBar3;
	}

	/**
	 * This method initializes jButtonComenzar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonComenzar() {
		if (jButtonComenzar == null) {
			jButtonComenzar = new JButton();
			jButtonComenzar.setBounds(new Rectangle(462, 288, 162, 51));
			jButtonComenzar.setText("Comenzar");
			jButtonComenzar.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					 Random numAleatorio1;

				     numAleatorio1 = new Random ();
				     Random numAleatorio2;

				        numAleatorio2 = new Random ();

				        Random numAleatorio3;

				        numAleatorio3 = new Random ();


					
					Thread hilo=new BarThread(jProgressBar1);
					((BarThread) hilo).setDELAY(numAleatorio1.nextInt(100));
					
					
					Thread hilo2=new BarThread(jProgressBar2);
					((BarThread) hilo2).setDELAY(numAleatorio2.nextInt(100));
					
					
					Thread hilo3=new BarThread(jProgressBar3);
					((BarThread) hilo3).setDELAY(numAleatorio3.nextInt(100));
					
					((BarThread) hilo).comenzar();
					((BarThread) hilo2).comenzar();
					((BarThread) hilo3).comenzar();
					
					
		    	    
				}
			});
		}
		return jButtonComenzar;
	}
	public void run(final JProgressBar progressBar,int DELAY) {
	      int minimum = progressBar.getMinimum();
	      int maximum = progressBar.getMaximum();
	      Runnable runner = new Runnable() {
	        public void run() {
	        
	          int value = progressBar.getValue();
	          progressBar.setValue(value + 1);
	          
	        }
	      };
	      for (int i = minimum; i < maximum; i++) {
	        try {
	          SwingUtilities.invokeAndWait(runner);
	          // our job for each step is to just sleep
	          Thread.sleep(DELAY);
	        } catch (InterruptedException ignoredException) {
	        } catch (InvocationTargetException ignoredException) {
	        }
	      }
	      }
	       
	        
	      

}  //  @jve:decl-index=0:visual-constraint="10,10"
